<?php


namespace app\home\controller\game;


use app\common\model\GameRecords;
use app\common\model\Luzhu;
use app\home\controller\Base;
use app\home\service\CardSettlementService;
use app\home\service\TransferBetService;
use app\validate\home\BetOrder as validates;
use think\exception\ValidateException;

/** 已经弃用了，现在使用消息队列 queue
 * 开奖控制器
 * Class GameOpen
 * @package app\home\controller\game
 */
class GameOpen extends Base
{
    public $luzhuModel;
    public $OddsModel;

    public function initialize()
    {
        $this->luzhuModel = new Luzhu();
        //$this->OddsModel = new GameRecords();

        parent::initialize(); // TODO: Change the autogenerated stub
    }

    //开牌
    public function open_brand(): string
    {
        //开牌以后，写入露珠开牌信息
        $postField = 'table_id,game_type,result,xue_number,pu_number,result_pai';
        $post = $this->request->only(explode(',', $postField), 'post', null);

        try {
            validate(validates::class)->scene('lz_order')->check($post);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            return show([], config('ToConfig.http_code.error'), $e->getMessage());
        }

        if ($this->luzhuModel->where($post)->find()) {
            return show([], config('ToConfig.http_code.error'), '已经开牌过了');
        }

        return (new CardSettlementService())->open_game($post);

    }


}